package org.example.day12;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 5.1.1.2 方法schedule(TimerTask task,long delay)
 *      ②计划时间在过去
 */
public class MyThread8 {
    private static Timer timer = new Timer();

    static public class MyTask extends TimerTask {
        @Override
        public void run() {
            System.out.println("运行了！时间为: " + new Date());
        }
    }

    public static void main(String[] args) {
        try {
            MyThread7.MyTask task = new MyThread7.MyTask();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateString = "2010-10-12 09:08:00";
            Date dateRef = sdf.parse(dateString);
            System.out.println("当前时间: " + new Date().toLocaleString() + " 字符串时间: " + dateRef.toLocaleString());
            timer.schedule(task, dateRef);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
